<template>
  <div>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/platform/myCenter' }">个人中心</el-breadcrumb-item>
      <el-breadcrumb-item>我的考试</el-breadcrumb-item>
    </el-breadcrumb>
      <div style="margin-top: 12px;border: 1px solid #eeeeee;border-top: 3px solid #499aff">
        <div style="margin-left: 15px;float:left;margin-top: 8px;margin-bottom: 6px"><img style="align-content: center" src="../assets/stu/ico_test_hover.png" height="32" width="32"/></div>
        <div style="float: left;vertical-align: middle;line-height: 50px;margin-left: 10px;color: #499aff">当前考试</div>
      <el-table :data="currentData" highlight-current-row v-loading="loading" style="width: 100%">
        <el-table-column
          type="index">
        </el-table-column>
        <el-table-column
          prop="exam"
          label="试卷名称"
          width="200"
        >
        </el-table-column>
        <el-table-column
          prop="time"
          label="考试时间(min)"
          width="200">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="small"
              @click="goLearn(scope.row)">开始考试</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="margin-top: 12px;border: 1px solid #eeeeee;border-top: 3px solid #ff5d44">
      <div style="margin-left: 15px;float:left;margin-top: 8px;margin-bottom: 6px"><img style="align-content: center" src="../assets/stu/ico_list_history.png" height="32" width="32"/></div>
      <div style="float: left;vertical-align: middle;line-height: 50px;margin-left: 10px;color: #ff5d44">历史考试</div>
      <el-table :data="currentData" highlight-current-row v-loading="loading" style="width: 100%">
        <el-table-column
          type="index">
        </el-table-column>
        <el-table-column
          prop="exam"
          label="试卷名称"
          width="200"
        >
        </el-table-column>
        <el-table-column
          prop="time"
          label="考试时间(min)"
          width="200">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="small"
              @click="goLearn(scope.row)">查看试卷</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  import {stuGetExam} from '@/api/api'
  export default {
    data () {
      return {
        loading: false,
        currentData: [],
        historyData: []
      }
    },
    created () {
      this.initData()
    },
    methods: {
      // 获取设备名称
      async initData () {
        this.loading = true
        try {
          stuGetExam().then((res) => {
            this.currentData = res.data  // type 看下转换下，通过store获取
            this.loading = false
          })
        } catch (err) {
          console.log('获取数据失败', err)
        }
      },
      goLearn (row) {
        this.$router.push({name: '考卷详情', params: {examId: row.pid}})
      }
    }
  }
</script>

<style scoped lang="less">
  div{
    .el-breadcrumb {
      margin-top: 10px;
    }
  }
</style>
